home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
tptc16.zip
/
TPCSYM.INC
< prev
next >
Wrap
Text File
|
1993-01-04
|
4KB
|
194 lines
(*
* TPTC - Turbo Pascal to C translator
*
* (C) 1988 Samuel H. Smith (rev. 13-Feb-88)
*
*)
function findsym( table: symptr;
id: string40): symptr;
{locate a symbol in a specified symbol table. returns pointer to
the entry if found, otherwise nil is returned}
var
sym: symptr;
begin
stoupper(id);
past_marker := false;
sym := table;
while sym <> nil do
begin
if sym^.id = id then
begin
findsym := sym; {symbol found}
exit;
end;
if sym^.id = localseprt then
past_marker := true;
sym := sym^.next;
end;
findsym := nil; {symbol not found}
end;
function locatesym(id: string40): symptr;
{locate a symbol in either the local or the global symbol table.
returns the symbol table entry pointer, if found. returns
nil when not in either table}
var
sym: symptr;
begin
in_globals := false;
in_locals := false;
sym := findsym(locals,id);
if sym <> nil then
in_locals := true
else
begin
sym := findsym(globals,id);
if sym <> nil then
in_globals := true
end;
locatesym := sym;
end;
procedure addsym( var table: symptr;
id: string40;
symtype: symtypes;
suptype: supertypes;
parcount: integer;
vv: integer;
lim: integer);
{add a symbol to a specific symbol table.
does not add(or change) the symbol if a duplicate entry is found}
var
sym: symptr;
begin
sym := nil;
if unitlevel = 0 then
sym := findsym( table,id );
if sym = nil then
begin
if maxavail-300 > sizeof(sym^) then
begin
new(sym);
stoupper(id);
sym^.id := id;
sym^.symtype := symtype;
sym^.suptype := suptype;
sym^.parcount := parcount;
sym^.limit := lim;
sym^.pvar := vv;
sym^.parent := nil;
sym^.next := table;
table := sym;
{writeln(' add id=',id,' type=',ord(symtype),' par=',parcount);}
end
else
begin
write(con, ^G^G^G,'TPTC: Out of memory');
halt;
end;
end;
end;
procedure newsym( id: string40;
symtype: symtypes;
suptype: supertypes;
parcount: integer;
vv: integer;
lim: integer);
{enter a new symbol into the current symbol table (local or global)}
begin
if unitlevel = 0 then
addsym(globals,id,symtype,suptype,parcount,vv,lim)
else
addsym(locals,id,symtype,suptype,parcount,vv,lim);
end;
procedure purgetable( var table: symptr );
{purge all entries from the specified symbol table}
var
sym: symptr;
sn: integer;
begin
if dumpsymbols then
begin
writeln(ofd[level]);
writeln(ofd[level],' /* Symbol table:');
sym := table; sn := 0;
while sym <> nil do
begin
if (sn mod 20) = 0 then
writeln(ofd[level],
' *',^M^J,' * ',
ljust('Name',identlen),
'Par Supertype Type Limit',^M^J,
' * ------------------------------------------------------');
writeln(ofd[level],' * ',
LJUST(sym^.id,identlen), sym^.parcount:3,' ',
LJUST(supertypename[sym^.suptype],15),
LJUST(typename[sym^.symtype],15),
sym^.limit);
sym := sym^.next;
inc(sn);
end;
writeln(ofd[level],' */');
writeln(ofd[level]);
writeln(ofd[level]);
end;
while table <> nil do
begin
sym := table;
table := table^.next;
dispose(sym);
end;
end;
procedure purgefrom(idn: string40);
{purge all entries from local symbol table starting with spec'd symbol}
var
sym: symptr;
begin
(* writeln(^M^J,'purge from ',idn);*)
while locals <> nil do
begin
sym := locals;
if locals^.id <> idn then
begin
locals := locals^.next;
if locals <> nil then
locals^.parent := nil;
(* writeln('dispose of local: ',sym^.id);*)
dispose(sym);
end
else
exit;
end;
end;